<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="姓名" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入姓名"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <!--      0：编辑；1：待审核；2：发布：3：取消发布；-->
      <el-form-item label="简历状态" prop="status">
        <el-select v-model="queryParams.status" placeholder="请选择简历状态" clearable size="small">
          <el-option
            v-for="dict in statusOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          ></el-option>
        </el-select>
      </el-form-item>
<!--      0：在校-实习；1：在校-找工作；2：在职-考虑机会；3：在职-月内到岗；5：在职-暂不考虑；6：离职-立即到岗-->
      <el-form-item label="在职状态" prop="workStatus">
        <el-select v-model="queryParams.workStatus" placeholder="请选择在职状态" clearable size="small">
          <el-option
            v-for="dict in workStatusOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          icon="el-icon-edit"
          size="mini"
          :disabled="multiple"
          @click="handleConfirm"
          v-hasPermi="['env:cv:edit']"
        >审核</el-button>
      </el-col>
        <el-col :span="1.5">
          <el-button
            type="success"
            icon="el-icon-edit"
            size="mini"
            :disabled="multiple"
            @click="handleConfirmCancel"
            v-hasPermi="['env:cv:edit']"
          >取消发布</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['env:cv:export']"
        >导出</el-button>
      </el-col>
	  <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="cvList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="ID" align="left" prop="id" />
      <el-table-column label="姓名" align="left" prop="name" :show-overflow-tooltip="true"/>
      <!--      0：编辑；1：待审核；2：发布：3：取消发布；-->
      <el-table-column label="简历状态" align="left" prop="status" :formatter="statusFormat"/>
<!--      1:高/中专及以下；2：大专：3：本科；4：硕士；5：博士及以上-->
      <el-table-column label="求职岗位" align="left" prop="reqPositon" :show-overflow-tooltip="true"/>
      <el-table-column label="期望薪资" align="left" prop="reqSalary" />
      <!--      0：在校-实习；1：在校-找工作；2：在职-考虑机会；3：在职-月内到岗；5：在职-暂不考虑；6：离职-立即到岗-->
      <el-table-column label="在职状态" align="left" prop="workStatus" :formatter="workStatusFormat" :show-overflow-tooltip="true"/>
      <el-table-column label="操作" align="left" width="180" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleConfirm(scope.row)"
            v-hasPermi="['env:cv:edit']"
          >审核</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleConfirmCancel(scope.row)"
            v-hasPermi="['env:cv:edit']"
          >取消发布</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['env:cv:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改简历信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="状态0：编辑；1：待审核；2：发布：3：取消发布；">
          <el-radio-group v-model="form.status">
            <el-radio label="1">请选择字典生成</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="简历编号" prop="cvNo">
          <el-input v-model="form.cvNo" placeholder="请输入简历编号" />
        </el-form-item>
        <el-form-item label="姓名" prop="name">
          <el-input v-model="form.name" placeholder="请输入姓名" />
        </el-form-item>
        <el-form-item label="头像" prop="photoUrl">
          <el-input v-model="form.photoUrl" placeholder="请输入头像" />
        </el-form-item>
        <el-form-item label="性别0:女；1:男" prop="sex">
          <el-select v-model="form.sex" placeholder="请选择性别0:女；1:男">
            <el-option label="请选择字典生成" value="" />
          </el-select>
        </el-form-item>
        <el-form-item label="年龄" prop="age">
          <el-input v-model="form.age" placeholder="请输入年龄" />
        </el-form-item>
        <el-form-item label="行业工龄" prop="workAge">
          <el-input v-model="form.workAge" placeholder="请输入行业工龄" />
        </el-form-item>
        <el-form-item label="出生日期" prop="birthday">
          <el-date-picker clearable size="small" style="width: 200px"
            v-model="form.birthday"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择出生日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="当前在职状态0：在校-实习；1：在校-找工作；2：在职-考虑机会；3：在职-月内到岗；5：在职-暂不考虑；6：离职-立即到岗">
          <el-radio-group v-model="form.workStatus">
            <el-radio label="1">请选择字典生成</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="毕业院校" prop="school">
          <el-input v-model="form.school" placeholder="请输入毕业院校" />
        </el-form-item>
        <el-form-item label="学历1:高/中专及以下；2：大专：3：本科；4：硕士；5：博士及以上" prop="qualifications">
          <el-input v-model="form.qualifications" placeholder="请输入学历1:高/中专及以下；2：大专：3：本科；4：硕士；5：博士及以上" />
        </el-form-item>
        <el-form-item label="毕业专业" prop="speciality">
          <el-input v-model="form.speciality" placeholder="请输入毕业专业" />
        </el-form-item>
        <el-form-item label="毕业时间" prop="graduateDate">
          <el-date-picker clearable size="small" style="width: 200px"
            v-model="form.graduateDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择毕业时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="求职岗位" prop="reqPositon">
          <el-input v-model="form.reqPositon" placeholder="请输入求职岗位" />
        </el-form-item>
        <el-form-item label="期望城市" prop="reqCity">
          <el-input v-model="form.reqCity" placeholder="请输入期望城市" />
        </el-form-item>
        <el-form-item label="期望行业" prop="reqIndustry">
          <el-input v-model="form.reqIndustry" placeholder="请输入期望行业" />
        </el-form-item>
        <el-form-item label="期望薪资" prop="reqSalary">
          <el-input v-model="form.reqSalary" placeholder="请输入期望薪资" />
        </el-form-item>
        <el-form-item label="自我描述" prop="selfDesc">
          <el-input v-model="form.selfDesc" placeholder="请输入自我描述" />
        </el-form-item>
        <el-form-item label="专业及擅长描述" prop="proDesc">
          <el-input v-model="form.proDesc" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="专家介绍类型为1时使用，富文本编辑" prop="cvDesc">
          <el-input v-model="form.cvDesc" placeholder="请输入专家介绍类型为1时使用，富文本编辑" />
        </el-form-item>
        <el-form-item label="简历" prop="cvUrl">
          <el-input v-model="form.cvUrl" placeholder="请输入简历" />
        </el-form-item>
        <el-form-item label="工作经历" prop="workHistory">
          <el-input v-model="form.workHistory" placeholder="请输入工作经历" />
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" placeholder="请输入备注" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listCv, getCv, delCv, addCv, updateCv, exportCv,confirmCv,confirmCancelCv } from "@/api/system/cv";

export default {
  name: "Cv",
  components: {
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 简历信息表格数据
      cvList: [],
      // 状态字典
      statusOptions: [],
      // 状态字典
      workStatusOptions: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        status: null,
        userName: null,
        workStatus: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
    this.getDicts("env_cv_status").then(response => {
      this.statusOptions = response.data;
    });
    this.getDicts("env_work_status").then(response => {
      this.workStatusOptions = response.data;
    });
  },
  methods: {
    /** 查询简历信息列表 */
    getList() {
      this.loading = true;
      listCv(this.queryParams).then(response => {
        this.cvList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 简历状态字典翻译
    statusFormat(row, column) {
      return this.selectDictLabel(this.statusOptions, row.status);
    },
    // 在职状态字典翻译
    workStatusFormat(row, column) {
      return this.selectDictLabel(this.workStatusOptions, row.workStatus);
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        status: 0,
        userName: null,
        workStatus: 0
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加简历信息";
    },
    /** 审核按钮操作 */
    handleConfirm(row) {
      const ids = row.id || this.ids;
      confirmCv(ids).then(response => {
        this.msgSuccess("审核成功");
        this.getList();
      })
    },
    /** 取消审核按钮操作 */
    handleConfirmCancel(row) {
      const ids = row.id || this.ids;
      confirmCancelCv(ids).then(response => {
        this.msgSuccess("取消成功");
        this.getList();
      })
    },

    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getCv(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改简历信息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateCv(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addCv(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除简历信息编号为"' + ids + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delCv(ids);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        })
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有简历信息数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return exportCv(queryParams);
        }).then(response => {
          this.download(response.msg);
        })
    }
  }
};
</script>
